package iosr11.gbase;

import com.google.api.gbase.client.GoogleBaseEntry;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.PlainTextConstruct;

public class StudentMarksBaseImpl implements MarkDAO {

	private MarkBase markBase;
	private BaseDAO engine;
	public StudentMarksBaseImpl(BaseDAO engine){
		this.engine = engine;
		markBase = new MarkBaseImpl(engine);
	}
	
	@Override
	public boolean addNewMarkToStudent(String studentId, String teacherId,
			float grade, int kind, DateTime date, float points) {
		String markId = markBase.addNewMarkReturnId(grade, teacherId, kind, date, points);
		if (markId==null)
			return false;
		GoogleBaseEntry entry = new GoogleBaseEntry();
		entry.setTitle(new PlainTextConstruct("Student marks"));
		entry.setDraft(true);
		entry.getGoogleBaseAttributes().setItemType("Student mark");
		entry.getGoogleBaseAttributes().addReferenceAttribute("student", studentId);
		entry.getGoogleBaseAttributes().addReferenceAttribute("mark", markId);
		
		return engine.addRecord(entry);
	}

}
